import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';

class CommonPicker{
  static Future<int> showPicker({BuildContext context, List<String> options, int value, double height = 300}){
    return showCupertinoModalPopup<int>(context: context, builder: (BuildContext context){
      var controller = FixedExtentScrollController(initialItem: value);
      var buttonTextStyle = TextStyle(
        fontSize: 18, 
        fontWeight: FontWeight.w500,
        color: Theme.of(context).primaryColor
      );
      return Container(
        height: height,
        color: Colors.grey.shade100,
        child: Column(
          children: [
            Container(
              height: 40.0,
              color: Colors.grey.shade300,
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  FlatButton(
                    onPressed: (){
                      Navigator.of(context).pop();
                    }, 
                    child: Text("取消", style: buttonTextStyle,)
                  ),
                  FlatButton(
                    onPressed: (){
                      Navigator.of(context).pop(controller.selectedItem);
                    }, 
                    child: Text("确定", style: buttonTextStyle,)
                  )
                ],
              ),
            ),
            Expanded(
              child: CupertinoPicker(
                backgroundColor: Theme.of(context).scaffoldBackgroundColor,
                scrollController: controller,
                itemExtent: 32.0,
                onSelectedItemChanged: (val) {},
                children: options.map((e) => Text(e)).toList(),
              ),
            )
          ],
        ),
      );
    });
  }
}